
<template>
  <div class="article-detail">
    <div class="back" @click="getBack">返回</div>
    <div class="title">{{articleObj.title}}</div>
    <div class="content" v-html="articleObj.content">

    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, getCurrentInstance, reactive, ref, toRefs } from 'vue'
import { useRouter, useRoute } from 'vue-router'
export default defineComponent({
  name: 'ArticleDetail',
  setup() {
    const router = useRouter()
    const route = useRoute()
    const state = reactive({
      articleObj: {}
    })

    onMounted(() => {
      console.log(route.params)
      state.articleObj = route.params
    })

    // 返回首页
    const getBack = () => {
      router.replace('/home')
    }

    return {
      ...toRefs(state),
      getBack
    }
  }
})
</script>

<style lang="scss" scoped>
.article-detail {
  position: relative;
  width: 70%;
  margin: 15px auto;
  background: #fff;
  padding: 20px;
  .title {
    font-size: 24px;
    font-weight: 500;
    text-align: center;
    margin-bottom: 20px;
  }
  .back {
    position: absolute;
    top: 30px;
    right: 30px;
    background: #80bd01;
    color: #fff;
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
  }
}
</style>
